<template>
	<view class="setting">
		<view class="list-block">
			<view class="box-flex-between" v-if="userInfo" @click="toEditUserInfo">
				<view class="box-flex-start my-user-box">
					<image :src="$util.showImage(userInfo.userPhoto)" mode="aspectFill" v-if="userInfo.userPhoto">
					</image>
					<image src="@/static/images/default_user.jpg" mode="aspectFill" v-else></image>
					<view>
						<view class="name"><text>{{userInfo.nikename}}</text></view>
						<view><text>账号：{{userInfo.username}}</text></view>
					</view>
				</view>
				<uni-icons type="forward"></uni-icons>
			</view>
			<view class="box-flex-between list-row" @click="toAccount">
				<view>账号与安全</view>
				<uni-icons type="forward"></uni-icons>
			</view>
		</view>
		<!-- #ifdef APP-PLUS -->
		<view class="list-block">
			<view class="box-flex-between list-row" @click="toAppSetting">
				<view>系统通知</view>
				<view>
					<text>{{noticeAuth ? '已开启' : '去开启'}}</text>
					<uni-icons type="forward"></uni-icons>
				</view>
			</view>
			<view class="box-flex-between list-row" @click="toPrivacy">
				<view>隐私政策</view>
				<uni-icons type="forward"></uni-icons>
			</view>
			<view class="box-flex-between list-row" @click="toPermissions">
				<view>应用权限</view>
				<uni-icons type="forward"></uni-icons>
			</view>
		</view>
		<!-- #endif -->
		<view class="list-block">
			<view class="box-flex-between list-row" @click="toFeedback">
				<view>帮助与反馈</view>
				<uni-icons type="forward"></uni-icons>
			</view>
			<view class="box-flex-between list-row" @click="toAppInfo">
				<view>关于jeeidp</view>
				<uni-icons type="forward"></uni-icons>
			</view>
		</view>
		<view class="list-block" @click="logoutDialog = true">
			<view class="logout-btn">退出登录</view>
		</view>
		<cu-dialog :show="logoutDialog" message="您确定要退出登录" @confirm="logout" @cancel="logoutDialog = false"></cu-dialog>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {
					nikename: '',
					username: ''
				},
				logoutDialog: false,
				noticeAuth: true
			}
		},
		onLoad() {
			this.userInfo = getApp().globalData.userInfo
		},
		onShow() {
			this.getAppSetting()
		},
		methods: {
			logout() {
				this.logoutDialog = false;
				this.$api.post('/appLogin/logout').then(res => {
					if (res.code == '900') {
						this.$util.removeLoginToken();
						getApp().globalData.userInfo = null;
						uni.reLaunch({
							url: '/pages/index/index'
						})
					}
				})
			},
			toEditUserInfo() {
				uni.navigateTo({
					url: '/pagesMy/setting/editUserInfo'
				})
			},
			toAccount() {
				uni.navigateTo({
					url: '/pagesMy/setting/account/account'
				})
			},
			toAppSetting() {
				uni.openAppAuthorizeSetting({
					success(res) {
						console.log(res)
					}
				})
			},
			getAppSetting() {
				const setting = uni.getAppAuthorizeSetting()
				console.log(setting);
				if (setting.notificationAuthorized == 'authorized') {
					this.noticeAuth = true;
				} else {
					this.noticeAuth = false;
				}
			},
			toPrivacy() {
				const url = 'https://www.jikesports.com.cn/appMaterial/userPrivacyProtocol.html'
				uni.navigateTo({
					url: '/pages/common/webView',
					success: (res) => {
						res.eventChannel.emit('url', url)
					}
				})
			},
			toPermissions() {
				const url = 'https://www.jikesports.com.cn/appMaterial/userAuthDesc.html'
				uni.navigateTo({
					url: '/pages/common/webView',
					success: (res) => {
						res.eventChannel.emit('url', url)
					}
				})
			},
			toFeedback() {
				uni.navigateTo({
					url: '/pagesMy/setting/feedback'
				})
			},
			toAppInfo() {
				uni.navigateTo({
					url: '/pagesMy/setting/appInfo'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.setting {
		.my-user-box {
			image {
				width: 70px;
				height: 70px;
				border-radius: 35px;
				margin-right: 15px;
				border: 2px solid $uni-border-color;
			}

			.name {
				font-weight: 600;
				font-size: 16px;
				color: $uni-main-color;
				margin-bottom: 5px;
			}
		}

		.logout-btn {
			margin-right: 15px;
			text-align: center;
			color: $uni-main-color;
		}
	}
</style>
